<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <%@ include file="/module/js.jsp"%>
    <script>
        $(document)
            .ready(
                function() {
                    $('#btnBack').click(function() {
                        window.location.href = "${basePath}/partyActivity/list?hdType=${hdType}";
                    });

                    var json_dy_info = JSON.parse('${json}');
                    var data_canjia = [];
                    var data_qingjia = [];
                    $("#div1").dialog({
                        width : 'auto',
                        height : 'auto',
                        bgiframe : true,
                        modal : true,
                        draggable : true,
                        resizable : false,
                        title : '选择参与人员',
                        autoOpen : false,
                        buttons : {
                            '取消' : function() {
                                $(this).dialog('close');
                            },
                            '确定' : function() {
                                var data = [];
                                var selected_item = document.getElementById("toSelect");
                                var flag = $("#flag").val();
                                if(selected_item.length==null || selected_item.length==0){
                                    alert("请选择一项");
                                    return false;
                                }
                                for(var i=0;i<selected_item.length;i++){
                                    var dy_id = selected_item.options[i].value;
                                    for(var j=0;j<json_dy_info.length;j++){
                                        if(dy_id==json_dy_info[j].dYID){
                                            data.push({//往对象的末尾添加一个对象
                                                xM: json_dy_info[j].xM,
                                                dYID: json_dy_info[j].dYID,
                                                xB: json_dy_info[j].xB,
                                                partyBranch: json_dy_info[j].partyBranch.dZBMC
                                            });
                                        }
                                    }
                                }
                                //初始化表格数据
                                if(flag==1) {//参与人员
                                    data_canjia = getTargetJSON(data,data_canjia);
                                    drawTable("tpl_dy","dy_list_info_id",data_canjia);
                                }else if(flag==2){//请假人员
                                    data_qingjia = getTargetJSON(data,data_qingjia);
                                    drawTable("tpl_dy_qingjia","dy_qingjia_list_info_id",data_qingjia);
                                }
                                $("#div1").dialog('close');
                            }
                        }
                    });

                    $("#delSelect").click(function(){
                        var iii = $.getSelectIds('dyItems');
                        if(iii.length==0){
                            alert('请至少选择一项删除');
                            return false;
                        }
                        $("input:checkbox[name='dyItems']:checked").each(function() {
                            removeObjFromJSON($(this).val(),data_canjia);
                        });
                        drawTable("tpl_dy","dy_list_info_id",data_canjia);
                    });

                    $("#delSelect1").click(function(){
                        var iii = $.getSelectIds('dyItems1');
                        if(iii.length==0){
                            alert('请至少选择一项删除');
                            return false;
                        }
                        $("input:checkbox[name='dyItems1']:checked").each(function() {
                            removeObjFromJSON($(this).val(),data_qingjia);
                        });
                        drawTable("tpl_dy_qingjia","dy_qingjia_list_info_id",data_qingjia);
                    });

                    $.select2("selectall","dyItems");
                    $.select2("selectall1","dyItems1");


                    //保存
                    var _form=$("#partyActivityForm").validate();
                    $("#btnSave").click(function() {
                        if(_form.form()){
                            $("#addType").val("1");
                            $("#partyActivityForm").attr("action","${basePath}/partyActivity/add");
                            $("#partyActivityForm").submit();
                        }
                    });

                    //保存并添加
                    $("#btnSaveToAdd").click(function() {
                        if(_form.form()){
                            $("#addType").val("2");
                            $("#partyActivityForm").attr("action","${basePath}/partyActivity/add");
                            $("#partyActivityForm").submit();
                        }
                    });

                });
        function showdiv(flag) {
            $("#flag").val(flag);
            $("#toSelect").empty();
            $('#div1').dialog('open');
        }


        //判断是否已经存在该元素值
        function getTargetJSON(fromJSON,toJSON){
            if(toJSON==null || toJSON.length==0){
                toJSON = fromJSON;
            }else{
                for(var i=0;i<fromJSON.length;i++){
                    var dyID = fromJSON[i].dYID;
                    var isExist = 0;
                    for(var j=0;j<toJSON.length;j++){
                        if(dyID==toJSON[j].dYID){
                            isExist=1;
                        }
                    }
                    if(isExist==0){
                        toJSON.push(fromJSON[i]);
                    }
                }
            }
            return toJSON;
        }

        //从JSON中移除某个对象
        function removeObjFromJSON(dyID,targetJSON) {
            for(var i=0;i<targetJSON.length;i++){
                if(targetJSON[i].dYID == dyID) {
                    targetJSON.splice(i,1);
                }
            }
        }

        //输出表格数据
        function drawTable(tplId,table_id,data) {
            $("#"+table_id).html('');
            for(var k=0;k<data.length;k++){
                data[k].iindex = k;
                var html = template(tplId,data[k]);
                $("#"+table_id).html($("#"+table_id).html()+html);
            }
        }

    </script>
    <style type="text/css">
        .grid{font:12px arial,helvetica,sans-serif;border:1px solid #cccccc}
        .grid td{font:100% arial,helvetica,sans-serif;height:24px;padding:5px}
        .grid{width:100%;border-collapse:collapse}.grid th{background:#eeeeee;height:27px;line-height:27px;border:1px solid #cccccc;padding-left:5px}
        .grid td{border:1px solid #cccccc;padding-left:5px;text-align: center;}
    </style>
</head>
<body>
<div style="text-align: center;padding-bottom: 20px;">
    <c:choose>
        <c:when test="${hdType==1}">
            <span class="table-header">固定日活动</span>
        </c:when>
        <c:when test="${hdType==2}">
            <span class="table-header">社区服务与志愿参与</span>
        </c:when>
        <c:when test="${hdType==3}">
            <span class="table-header">宣传思想工作情况</span>
        </c:when>
        <c:when test="${hdType==4}">
            <span class="table-header">廉政建设分析会</span>
        </c:when>
    </c:choose>
</div>
<form action="#" id="partyActivityForm" name="partyActivityForm">
    <input type="hidden" name="token" value="${token}" />
    <input type="hidden" name="selected_item_ids" id="selected_item_ids" value=""/>
    <input type="hidden" name="flag" id="flag" value=""/>
    <input type="hidden" name="hdType" id="hdType" value="${hdType}"/>
    <input type="hidden" name="addType" id="addType" value=""/>
    <table cellpadding="0" cellspacing="0" border="0" class="table-border"
           width="80%">
        <tr>
            <td class="table-titleTD" style="width: 20%"><font
                    style="color: red;">*</font><c:choose>
				        <c:when test="${hdType==1}">
				           		活动	
				        </c:when>
				        <c:when test="${hdType==2}">
				               服务 	
				        </c:when>
				        <c:when test="${hdType==3}">
				             思想	
				        </c:when>
				        <c:when test="${hdType==4}">
				             会议
				        </c:when>
				    </c:choose>名称：</td>
            <td class="table-contentTD" style="width: 30%">
                ${partyActivity.hDMC }
            </td>
            <td class="table-titleTD" style="width: 20%"><font
                    style="color: red;">*</font><c:choose>
				        <c:when test="${hdType==1}">
				           		活动	
				        </c:when>
				        <c:when test="${hdType==2}">
				               服务 	
				        </c:when>
				        <c:when test="${hdType==3}">
				             思想	
				        </c:when>
				        <c:when test="${hdType==4}">
				             会议
				        </c:when>
				    </c:choose>日期：</td>
            <td class="table-contentTD" style="width: 30%">
              ${partyActivity.hDRQ}
            </td>
        </tr>
        <tr>
            <td class="table-titleTD"><font style="color: red;">*</font><c:choose>
				        <c:when test="${hdType==1}">
				           		活动	
				        </c:when>
				        <c:when test="${hdType==2}">
				               服务 	
				        </c:when>
				        <c:when test="${hdType==3}">
				             思想	
				        </c:when>
				        <c:when test="${hdType==4}">
				             会议
				        </c:when>
				    </c:choose>时间：</td>
            <td class="table-contentTD">
					${partyActivity.hDSJ}
			</td>

            <td class="table-titleTD"><font style="color: red;">*</font><c:choose>
				        <c:when test="${hdType==1}">
				           		活动	
				        </c:when>
				        <c:when test="${hdType==2}">
				               服务 	
				        </c:when>
				        <c:when test="${hdType==3}">
				             思想	
				        </c:when>
				        <c:when test="${hdType==4}">
				             会议
				        </c:when>
				    </c:choose>地点：</td>
            <td class="table-contentTD">
					${partyActivity.hDDD}          
			</td>
        </tr>
        <tr>
            <td class="table-titleTD"><font style="color: red;">*</font><c:choose>
				        <c:when test="${hdType==1}">
				           		活动	
				        </c:when>
				        <c:when test="${hdType==2}">
				               服务 	
				        </c:when>
				        <c:when test="${hdType==3}">
				             思想	
				        </c:when>
				        <c:when test="${hdType==4}">
				             会议
				        </c:when>
				    </c:choose>主题：</td>
            <td class="table-contentTD" colspan="3">
					${partyActivity.hDZT}                
			</td>
        </tr>
        <tr>
            <td class="table-titleTD"><font style="color: red;">*</font><c:choose>
				        <c:when test="${hdType==1}">
				           		活动	
				        </c:when>
				        <c:when test="${hdType==2}">
				               服务 	
				        </c:when>
				        <c:when test="${hdType==3}">
				             思想	
				        </c:when>
				        <c:when test="${hdType==4}">
				             会议
				        </c:when>
				    </c:choose>内容：</td>
            <td class="table-contentTD" colspan="3">
                ${partyActivity.hDNR}                
            </td>
        </tr>
       
        <tr>
            <td colspan="4">
                <table class="grid" id="tb_dy_id">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>所在党支部</th>
                    </tr>
                    </thead>
                    <tbody id="dy_list_info_id">
							<c:forEach items="${partyActivityMembers}" var="datalist" varStatus="index">
								<tr>
									<td>${index.index+1 }</td>
									<td>
										 ${datalist.xM }
									</td>
									<td>
										 ${datalist.xB }
									</td>
									<td>
										 ${datalist.partyBranch }
									</td>
								</tr>
							</c:forEach>
                    </tbody>
                </table>
            </td>
        </tr>


        <tr>
            <td colspan="4">
                <table class="grid" id="tb_dy_qingjia_id">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>所在党支部</th>
                        <th>请假类别</th>
                        <th>请假事由</th>
                    </tr>
                    </thead>
                    <tbody id="dy_qingjia_list_info_id">
							<c:forEach items="${partyActivityMembersQingjia}" var="datalist" varStatus="index">
								<tr>
									<td>${index.index+1 }</td>
									<td>
										 ${datalist.xM }
									</td>
									<td>
										 ${datalist.xB }
									</td>
									<td>
										 ${datalist.partyBranch }
									</td>
									<td>
										 ${datalist.qJLB }
									</td>
									<td>
										 ${datalist.qJYY }
									</td>
									
								</tr>
							</c:forEach>
                    </tbody>
                </table>
            </td>
        </tr>

    </table>

    <br />
    <table cellpadding="1" cellspacing="1" border="0" align="left">
        <tr>
            <td><input id="btnGo2EditPage" class="inputButton "  autocomplete="off" value="修改" /></td>
			<td><input id="btnBackList" class="inputButton " autocomplete="off" value="返回" /></td>
        </tr>
    </table>

    <div id="div1" style="display: none;">
        <table cellpadding="0" cellspacing="0" border="0"
               class="table-border">

            <tr>
                <td style="clear:both; width: 45%">
                    <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"/><font color="green">在此查找</font> <br/>
                    <br/><label style="color:red;">未选中:</label><br/>
                    <select name="fromSelect" id="fromSelect" multiple="multiple" style="width:400px; height: 300px;"
                            ondblclick="moveField('fromSelect','toSelect');">
                        <c:forEach items="${partyLeagueMember}" var="data">
                            <option value="${data.dYID}">${data.xM}</option>
                        </c:forEach>
                    </select>
                    <select name="sourseFromSelect2" id="sourseFromSelect2" multiple="multiple" style="width: 220px; height: 150px; display: none;" >
                        <c:forEach items="${partyLeagueMember}" var="data">
                            <option value="${data.dYID}">${data.xM}</option>
                        </c:forEach>
                    </select>
                </td>
                <td align="center" style="width: 10%">
                    <input type="button"  onclick="moveAllField('fromSelect','toSelect');" style="width: 50px;" value=">>" />
                    <br>
                    <br/>
                    <input type="button"
                           onclick="moveField('fromSelect','toSelect');"
                           style="width: 50px;" value=">" />
                    <br/>
                    <br/>
                    <input type="button"   style="width: 50px;" value="&lt" onclick="moveField('toSelect','fromSelect');"/><br/> <br/>
                    <input type="button" style="width: 50px;" onclick="moveAllField('toSelect','fromSelect');"  value="&lt&lt" />
                </td>
                <td style="width: 45%"><br/><label style="color:red;">已选中:</label><br/>
                    <select name="toSelect" id="toSelect" multiple="multiple"  class="text"   style="width:400px;height: 300px;" ondblclick="moveField('toSelect','fromSelect');">
                    </select>
                </td>

            </tr>
        </table>
    </div>

</form>
<script>
		$(document).ready(function() {
			//点击修改跳转编辑页面
			$("#btnGo2EditPage").click(function() {
			   	window.location.href='${basePath}/partyActivity/premodify?hdType=${hdType}&id=${partyActivity.hDID}';
			});
			
			//点击返回，回到列表页面	
			$("#btnBackList").click(function() {
			   	window.location.href = "${basePath}/partyActivity/list?hdType=${hdType}";
			});
			
		 	if("${msg}"!=""){
			   	layer.alert("${msg}", {icon: 6});
		  	}
		});
		//compareListValue(document.getElementById('mz'),'${student.mz}');
	</script>
</body>
</html>
